package com.kawaiior.asoulworld.item.weapon;

import com.kawaiior.asoulworld.item.ItemSwordBase;
import com.kawaiior.asoulworld.util.EntityUtil;
import net.minecraft.entity.Entity;
import net.minecraft.entity.effect.EntityLightningBolt;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.MobEffects;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ActionResult;
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumHand;
import net.minecraft.world.World;

public class ItemCelestialLightSword extends ItemSwordBase {

    public ItemCelestialLightSword(String name, ToolMaterial material) {
        super(name, material);
        useable = true;
    }



//    public void onPlayerStoppedUsing(ItemStack stack, World worldIn, EntityLivingBase entityLiving, int timeLeft)
//    {
//        if (!useable)
//        {
//            return;
//        }
//
//        onCreatureStoppedUsing(stack, worldIn, entityLiving, timeLeft);
//        entityLiving.swingArm(entityLiving.getHeldItemMainhand() == stack ? EnumHand.MAIN_HAND : EnumHand.OFF_HAND);
//
//        if (!worldIn.isRemote)
//        {
//            if (entityLiving instanceof EntityPlayer)
//            {
//                EntityPlayer entityplayer = (EntityPlayer)entityLiving;
//                {
//                    entityplayer.getCooldownTracker().setCooldown(this, getCoolDownTicks(stack));
//                }
//            }
//        }
//    }
//
//    public void onCreatureStoppedUsing(ItemStack stack, World worldIn, EntityLivingBase entityLiving, int timeLeft)
//    {
//
//    }

    @Override
    public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn) {
        if(!useable)
        {
            return new ActionResult<ItemStack>(EnumActionResult.PASS, playerIn.getHeldItem(handIn));
        }
        if (worldIn.isRemote)
        {
            return new ActionResult<ItemStack>(EnumActionResult.PASS, playerIn.getHeldItem(handIn));
        }
        EntityUtil.ApplyBuff(playerIn, MobEffects.RESISTANCE,4,1);
        worldIn.addWeatherEffect((Entity)new EntityLightningBolt(worldIn,playerIn.posX+2,playerIn.posY,playerIn.posZ+2,false));
        worldIn.addWeatherEffect((Entity)new EntityLightningBolt(worldIn,playerIn.posX-2,playerIn.posY,playerIn.posZ+2,false));
        worldIn.addWeatherEffect((Entity)new EntityLightningBolt(worldIn,playerIn.posX-2,playerIn.posY,playerIn.posZ-2,false));
        worldIn.addWeatherEffect((Entity)new EntityLightningBolt(worldIn,playerIn.posX+2,playerIn.posY,playerIn.posZ-2,false));
        playerIn.getCooldownTracker().setCooldown(this,20);
        return new ActionResult<ItemStack>(EnumActionResult.SUCCESS,playerIn.getHeldItemMainhand());
    }
}
